.class Lcom/hyphenate/chat/EMChatManager$2;
.super Ljava/lang/Object;

# interfaces
.implements Ljava/lang/Runnable;


# instance fields
.field final synthetic this$0:Lcom/hyphenate/chat/EMChatManager;

.field final synthetic val$conv:Lcom/hyphenate/chat/EMConversation;

.field final synthetic val$msg:Lcom/hyphenate/chat/EMMessage;


# direct methods
.method constructor <init>(Lcom/hyphenate/chat/EMChatManager;Lcom/hyphenate/chat/EMMessage;Lcom/hyphenate/chat/EMConversation;)V
    .locals 0

    iput-object p1, p0, Lcom/hyphenate/chat/EMChatManager$2;->this$0:Lcom/hyphenate/chat/EMChatManager;

    iput-object p2, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    iput-object p3, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$conv:Lcom/hyphenate/chat/EMConversation;

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method


# virtual methods
.method public run()V
    .locals 11

    const/4 v10, 0x1

    const/4 v1, 0x0

    :try_start_0
    iget-object v0, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    invoke-virtual {v0}, Lcom/hyphenate/chat/EMMessage;->getType()Lcom/hyphenate/chat/EMMessage$Type;

    move-result-object v0

    sget-object v2, Lcom/hyphenate/chat/EMMessage$Type;->IMAGE:Lcom/hyphenate/chat/EMMessage$Type;

    if-ne v0, v2, :cond_5

    iget-object v0, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    sget-object v2, Lcom/hyphenate/chat/EMMessage$Status;->INPROGRESS:Lcom/hyphenate/chat/EMMessage$Status;

    invoke-virtual {v0, v2}, Lcom/hyphenate/chat/EMMessage;->setStatus(Lcom/hyphenate/chat/EMMessage$Status;)V

    iget-object v0, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    invoke-virtual {v0}, Lcom/hyphenate/chat/EMMessage;->getBody()Lcom/hyphenate/chat/EMMessageBody;

    move-result-object v0

    check-cast v0, Lcom/hyphenate/chat/EMImageMessageBody;

    if-nez v0, :cond_0

    new-instance v0, Lcom/hyphenate/chat/EMChatManager$1HandleError;

    iget-object v1, p0, Lcom/hyphenate/chat/EMChatManager$2;->this$0:Lcom/hyphenate/chat/EMChatManager;

    const/4 v2, 0x1

    const-string/jumbo v3, "Message body can not be null"

    iget-object v4, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    invoke-direct {v0, v1, v2, v3, v4}, Lcom/hyphenate/chat/EMChatManager$1HandleError;-><init>(Lcom/hyphenate/chat/EMChatManager;ILjava/lang/String;Lcom/hyphenate/chat/EMMessage;)V

    :goto_0
    return-void

    :cond_0
    invoke-virtual {v0}, Lcom/hyphenate/chat/EMImageMessageBody;->getLocalUrl()Ljava/lang/String;

    move-result-object v3

    new-instance v2, Ljava/io/File;

    invoke-direct {v2, v3}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    invoke-virtual {v2}, Ljava/io/File;->exists()Z

    move-result v4

    if-eqz v4, :cond_1

    invoke-virtual {v2}, Ljava/io/File;->canRead()Z

    move-result v2

    if-nez v2, :cond_2

    :cond_1
    new-instance v0, Lcom/hyphenate/chat/EMChatManager$1HandleError;

    iget-object v1, p0, Lcom/hyphenate/chat/EMChatManager$2;->this$0:Lcom/hyphenate/chat/EMChatManager;

    const/16 v2, 0x191

    const-string/jumbo v3, "File not exists or can not be read"

    iget-object v4, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    invoke-direct {v0, v1, v2, v3, v4}, Lcom/hyphenate/chat/EMChatManager$1HandleError;-><init>(Lcom/hyphenate/chat/EMChatManager;ILjava/lang/String;Lcom/hyphenate/chat/EMMessage;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    :catch_0
    move-exception v0

    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    new-instance v0, Lcom/hyphenate/chat/EMChatManager$1HandleError;

    iget-object v1, p0, Lcom/hyphenate/chat/EMChatManager$2;->this$0:Lcom/hyphenate/chat/EMChatManager;

    const-string/jumbo v2, "send message failed"

    iget-object v3, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    invoke-direct {v0, v1, v10, v2, v3}, Lcom/hyphenate/chat/EMChatManager$1HandleError;-><init>(Lcom/hyphenate/chat/EMChatManager;ILjava/lang/String;Lcom/hyphenate/chat/EMMessage;)V

    goto :goto_0

    :cond_2
    :try_start_1
    invoke-virtual {v0}, Lcom/hyphenate/chat/EMImageMessageBody;->isSendOriginalImage()Z

    move-result v2

    if-nez v2, :cond_4

    iget-object v2, p0, Lcom/hyphenate/chat/EMChatManager$2;->this$0:Lcom/hyphenate/chat/EMChatManager;

    iget-object v2, v2, Lcom/hyphenate/chat/EMChatManager;->mClient:Lcom/hyphenate/chat/EMClient;

    invoke-virtual {v2}, Lcom/hyphenate/chat/EMClient;->getContext()Landroid/content/Context;

    move-result-object v2

    invoke-static {v2, v3}, Lcom/hyphenate/util/ImageUtils;->getScaledImage(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v2, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v4

    if-nez v4, :cond_4

    new-instance v1, Ljava/io/File;

    invoke-direct {v1, v2}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    new-instance v4, Ljava/io/File;

    invoke-direct {v4, v3}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    invoke-virtual {v4}, Ljava/io/File;->length()J

    move-result-wide v4

    invoke-virtual {v1}, Ljava/io/File;->length()J

    move-result-wide v6

    const-wide/16 v8, 0x0

    cmp-long v1, v4, v8

    if-nez v1, :cond_3

    const-string/jumbo v0, "EMChatManager"

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v2, "original image size:"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, v4, v5}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V

    new-instance v0, Lcom/hyphenate/chat/EMChatManager$1HandleError;

    iget-object v1, p0, Lcom/hyphenate/chat/EMChatManager$2;->this$0:Lcom/hyphenate/chat/EMChatManager;

    const/16 v2, 0x191

    const-string/jumbo v3, "original image size is 0"

    iget-object v4, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    invoke-direct {v0, v1, v2, v3, v4}, Lcom/hyphenate/chat/EMChatManager$1HandleError;-><init>(Lcom/hyphenate/chat/EMChatManager;ILjava/lang/String;Lcom/hyphenate/chat/EMMessage;)V

    goto/16 :goto_0

    :cond_3
    const-string/jumbo v1, "EMChatManager"

    new-instance v8, Ljava/lang/StringBuilder;

    invoke-direct {v8}, Ljava/lang/StringBuilder;-><init>()V

    const-string/jumbo v9, "original image size:"

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8, v4, v5}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v8

    const-string/jumbo v9, " scaled image size:"

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8, v6, v7}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v8

    const-string/jumbo v9, " ratio:"

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    div-long v4, v6, v4

    long-to-int v4, v4

    invoke-virtual {v8, v4}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v4

    const-string/jumbo v5, "%"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-static {v1, v4}, Lcom/hyphenate/util/EMLog;->d(Ljava/lang/String;Ljava/lang/String;)V

    invoke-virtual {v0, v2}, Lcom/hyphenate/chat/EMImageMessageBody;->setLocalUrl(Ljava/lang/String;)V

    move-object v1, v3

    :goto_1
    invoke-static {v2}, Lcom/hyphenate/util/ImageUtils;->getBitmapOptions(Ljava/lang/String;)Landroid/graphics/BitmapFactory$Options;

    move-result-object v3

    iget v4, v3, Landroid/graphics/BitmapFactory$Options;->outWidth:I

    iget v3, v3, Landroid/graphics/BitmapFactory$Options;->outHeight:I

    invoke-virtual {v0, v4, v3}, Lcom/hyphenate/chat/EMImageMessageBody;->setSize(II)V

    new-instance v3, Ljava/io/File;

    invoke-direct {v3, v2}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    invoke-virtual {v3}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v0, v2}, Lcom/hyphenate/chat/EMImageMessageBody;->setFileName(Ljava/lang/String;)V

    move-object v0, v1

    :goto_2
    iget-object v1, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    invoke-virtual {v1}, Lcom/hyphenate/chat/EMMessage;->getMsgId()Ljava/lang/String;

    move-result-object v1

    iget-object v2, p0, Lcom/hyphenate/chat/EMChatManager$2;->this$0:Lcom/hyphenate/chat/EMChatManager;

    iget-object v3, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    iget-object v4, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$conv:Lcom/hyphenate/chat/EMConversation;

    # invokes: Lcom/hyphenate/chat/EMChatManager;->setMessageSendCallback(Lcom/hyphenate/chat/EMMessage;Lcom/hyphenate/chat/EMConversation;Ljava/lang/String;Ljava/lang/String;)V
    invoke-static {v2, v3, v4, v1, v0}, Lcom/hyphenate/chat/EMChatManager;->access$300(Lcom/hyphenate/chat/EMChatManager;Lcom/hyphenate/chat/EMMessage;Lcom/hyphenate/chat/EMConversation;Ljava/lang/String;Ljava/lang/String;)V

    iget-object v0, p0, Lcom/hyphenate/chat/EMChatManager$2;->this$0:Lcom/hyphenate/chat/EMChatManager;

    iget-object v0, v0, Lcom/hyphenate/chat/EMChatManager;->emaObject:Lcom/hyphenate/chat/adapter/EMAChatManager;

    iget-object v1, p0, Lcom/hyphenate/chat/EMChatManager$2;->val$msg:Lcom/hyphenate/chat/EMMessage;

    iget-object v1, v1, Lcom/hyphenate/chat/EMMessage;->emaObject:Lcom/hyphenate/chat/adapter/message/EMAMessage;

    invoke-virtual {v0, v1}, Lcom/hyphenate/chat/adapter/EMAChatManager;->sendMessage(Lcom/hyphenate/chat/adapter/message/EMAMessage;)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    goto/16 :goto_0

    :cond_4
    move-object v2, v3

    goto :goto_1

    :cond_5
    move-object v0, v1

    goto :goto_2
.end method
